/**************************************************************

This do file creates the appendix tables and figures in Abarcar and Theoharides

**************************************************************/
capture log close
capture program drop _all
capture macro drop _all
estimates drop _all
set matsize 2000
drop _all
set more off

*UPDATE PATH NAMES;
global ched_data 
global output 

***************************************************************
#delimit ;
log using "${output}app_analysis.log", replace;

use "${ched_data}analysis_sample.dta", clear ;

xtset provcode year;

*SET CONTROLS;
global controls_yr emp_f_2564_90_yr* emp_m_2564_90_yr* female_90_yr* age_90_yr* nurse_cen_pc90_yr*;
global controls_yr_full emp_f_2564_90_yr* emp_m_2564_90_yr* female_90_yr* age_90_yr* nurse_cen_pc90_yr* _yrschl_2564_90_yr* urban_90_yr*  ;

*Set up;
replace ttrend=ttrend-12; 
gen ttrend_high1=ttrend*high1;

gen post2000_high=post2000*high1;
gen post2000_trend=post2000_high*(ttrend-1);

gen post2007_high=post2007*high1;
gen post2007_trend=post2007_high*(ttrend-1);
replace post2007_trend=post2007_trend-7 if post2007_trend!=0; 

*2003 and 2010 as four years ahead;
gen ttrend_three=ttrend-3;
gen ttrend_three_high1=ttrend_three*high1;

gen post2003_high=post2003*high1;
gen post2003_trend_three=post2003_high*(ttrend_three-1);

gen post2010_high=post2010*high1;

gen post2010_trend_three=post2010_high*(ttrend_three-1);
replace post2010_trend_three=post2010_trend_three-7 if post2010_trend_three!=0; 

tab year, gen(yr); 

gen migrate_nonUSnurse_hth=((nonnurse+nurse-nurseUSA)/(totpop/100000));
gen migrate_othernurse_hth=((nurse-nurseUSA)/(totpop/100000));

*non-nurse migration and non-US nurse migration rate x year FE;
gen temp2=migrate_nonnurse if year==1990;
bys province: egen migrate_nonnurse1990=max(temp2);
drop temp2;

gen temp2=migrate_othernurse if year==1990;
bys province: egen migrate_othernurse1990=max(temp2);
drop temp2;

forvalues x=1/27 {;
	gen migrate_nonnurse_yr`x'=migrate_nonnurse1990*yr`x';
	gen migrate_othernurse_yr`x'=migrate_othernurse1990*yr`x';
	
};

*Create island x year fixed effects;
*Island=1 for Luzon, 2 for Visayas, and 3 for Mindanao;
gen island=1 if (regn>=1&regn<=5)|regn==13|regn==14|regn==17;
replace island=2 if regn>=6&regn<=8;
replace island=3 if (regn>=9&regn<=12)|regn==15|regn==16;

tab island, gen(islandfe);

*Create island x time fixed effects;
forvalues x=1/3 {;
	forvalues y=1/24 {;
		gen island_x_time_`x'_`y'=islandfe`x'*yr`y'; 
	};
};

*******************************************************************************;
*Appendix Table 1: Top 20 Nurse Migration Provinces to U.S.
*******************************************************************************;
tab migrateUSA_hth if year==1990, sort;

*******************************************************************************;
*Appendix Table 2: Summary Statistics;
*******************************************************************************;

gen pass_rate_grad=(passed/collegepop)*100;
replace pass_rate_grad=0 if examinees==.;
gen examinee_rate_grad=(examinees/collegepop)*100;
replace examinee_rate_grad=0 if examinees==.;

putexcel set "${output}/Final Tables", modify sheet("Summary Stats");

*Add labels;
putexcel A1:J1 = ("Table 1. Summary Statistics"), border("bottom") merge; 
putexcel C2:D2 = ("Full Sample") F2:G2 = ("High Nurse Migration Provinces") I2:J2 = ("Low Nurse Migration Provinces"), merge hcenter;
putexcel C3 = ("Mean") D3 = ("St. Dev.") F3 = ("Mean") G3 = ("St. Dev.") I3 = ("Mean") J3 = ("St. Dev."), hcenter;
putexcel C4 = ("(1)") D4 = ("(2)") F4 = ("(3)") G4 = ("(4)") I4 = ("(5)") J4 = ("(6)"), border("bottom") hcenter;
putexcel E4 H4, border("bottom");
putexcel C46:D46 = ("74") F46:G46 = ("37") I46:J46 = ("37"), hcenter merge;
putexcel C47:D47 = ("1702") F47:G47 = ("851") I47:J47 = ("851"), hcenter merge;
putexcel A48:J48 = ("Notes:"), merge border("top");

*Row Labels;
putexcel A5 = ("Panel A. All Years"), italic underline;
putexcel A6 = ("Migrants per 100,000"), italic;
putexcel B7 = ("Total");
putexcel B8 = ("U.S. Nurse");
putexcel B9 = ("Non-Nurse");

putexcel A10 = ("Post-Secondary Enrollment Rates (%)"), italic;
putexcel B11 = ("Total");
putexcel B12 = ("Nurse");
putexcel B13 = ("Other");

putexcel A14 = ("Post-Secondary Graduation Rates (%)"), italic;
putexcel B15 = ("Total");
putexcel B16 = ("Nurse");
putexcel B17 = ("Other");

putexcel A18 = ("Number of Nursing Programs"), italic;
putexcel B19 = ("Total");
putexcel B20 = ("Public");
putexcel B21 = ("Private");

putexcel A22 = ("Nursing Licensure Exam"), italic;
putexcel B23 = ("Examinee Rate (%)");
putexcel B24 = ("Pass Rate (%)");

putexcel A26 = ("Panel B. Pre-Period Years"), italic underline;
putexcel A27 = ("Migrants per 100,000"), italic;
putexcel B28 = ("Total");
putexcel B29 = ("U.S. Nurse");
putexcel B30 = ("Non-Nurse");

putexcel A31 = ("Post-Secondary Enrollment Rates (%)"), italic;
putexcel B32 = ("Total");
putexcel B33 = ("Nurse");
putexcel B34 = ("Other");

putexcel A35 = ("Post-Secondary Graduation Rates (%)"), italic;
putexcel B36 = ("Total");
putexcel B37 = ("Nurse");
putexcel B38 = ("Other");

putexcel A39 = ("Number of Nursing Programs"), italic;
putexcel B40 = ("Total");
putexcel B41 = ("Public");
putexcel B42 = ("Private");

putexcel A43 = ("Nursing Licensure Exam"), italic;
putexcel B44 = ("Examinee Rate (%)");
putexcel B45 = ("Pass Rate (%)");


putexcel A46 = ("Number of Provinces");
putexcel A47 = ("Observations (All years)");

foreach var of varlist migrate_total_hth migrateUSA_hth migrate_nonnurse_hth enroll_tot enroll_tot1 enroll_tot0 
	grad_tot grad_tot1 grad_tot0
	nurseprog nurseprog_public nurseprog_private 
	examinee_rate_grad pass_rate_grad
	{;
	
	if "`var'"=="migrate_total_hth" {; local t="7"; };	
	if "`var'"=="migrateUSA_hth" {; local t="8"; };
	if "`var'"=="migrate_nonnurse_hth" {; local t="9"; };
	if "`var'"=="enroll_tot1" {; local t="12"; };
	if "`var'"=="enroll_tot0" {; local t="13"; };
	if "`var'"=="enroll_tot" {; local t="11"; };
	if "`var'"=="grad_tot1" {; local t="16"; };
	if "`var'"=="grad_tot0" {; local t="17"; };
	if "`var'"=="grad_tot" {; local t="15"; };
	if "`var'"=="nurseprog" {; local t="19"; };
	if "`var'"=="nurseprog_private" {; local t="21"; };
	if "`var'"=="nurseprog_public" {; local t="20"; };
	if "`var'"=="examinee_rate_grad" {; local t="23"; };
	if "`var'"=="pass_rate_grad" {; local t="24"; };
	
	if "`var'"=="migrate_total_hth" {; local w="1990"; };	
	if "`var'"=="migrateUSA_hth" {; local w="1990"; };
	if "`var'"=="migrate_nonnurse_hth" {; local w="1990"; };
	if "`var'"=="enroll_tot1" {; local w="1990"; };
	if "`var'"=="enroll_tot0" {; local w="1990"; };
	if "`var'"=="enroll_tot" {; local w="1990"; };
	if "`var'"=="nurseprog" {; local w="1991"; };
	if "`var'"=="nurseprog_private" {; local w="1991"; };
	if "`var'"=="nurseprog_public" {; local w="1991"; };
	if "`var'"=="examinee_rate_grad" {; local w="1990"; };
	if "`var'"=="pass_rate_grad" {; local w="1990"; };
	if "`var'"=="grad_tot1" {; local w="1998"; };
	if "`var'"=="grad_tot0" {; local w="1998"; };
	if "`var'"=="grad_tot" {; local w="1998"; };
	
	if "`var'"=="migrate_total_hth" {; local z="0.000"; };	
	if "`var'"=="migrateUSA_hth" {; local z="0.000"; };
	if "`var'"=="migrate_nonnurse_hth" {; local z="0.000"; };
	if "`var'"=="enroll_tot1" {; local z="number_d2"; };
	if "`var'"=="enroll_tot0" {; local z="number_d2"; };
	if "`var'"=="enroll_tot" {; local z="number_d2"; };
	if "`var'"=="nurseprog" {; local z="number_d2"; };
	if "`var'"=="nurseprog_private" {; local z="number_d2"; };
	if "`var'"=="nurseprog_public" {; local z="number_d2"; };
	if "`var'"=="examinee_rate_grad" {; local z="0.000"; };
	if "`var'"=="pass_rate_grad" {; local z="0.000"; };
	if "`var'"=="grad_tot1" {; local z="number_d2"; };
	if "`var'"=="grad_tot0" {; local z="number_d2"; };
	if "`var'"=="grad_tot" {; local z="number_d2"; };
	
	*Full Sample;
	su `var' if year>=1991&year<=2013;
	scalar mean=r(mean);
	scalar sd=r(sd);
	putexcel C`t'=(`=mean') D`t'=(`=sd'), nformat(`z') hcenter;
	
	su `var' if year>=1991&year<=2013&high1==1;
	scalar mean=r(mean);
	scalar sd=r(sd);
	putexcel F`t'=(`=mean') G`t'=(`=sd'), nformat(`z') hcenter;
	
	su `var' if year>=1991&year<=2013&high1==0;
	scalar mean=r(mean);
	scalar sd=r(sd);
	putexcel I`t'=(`=mean') J`t'=(`=sd'), nformat(`z') hcenter;
	
	local t=`t'+21;
	*Baseline;
	su `var' if year>=1991&year<2000;
	scalar mean=r(mean);
	scalar sd=r(sd);
	putexcel C`t'=(`=mean') D`t'=(`=sd'), nformat(`z') hcenter;
	
	su `var' if year>=1991&year<2000&high1==1;
	scalar mean=r(mean);
	scalar sd=r(sd);
	putexcel F`t'=(`=mean') G`t'=(`=sd'), nformat(`z') hcenter;
	
	su `var' if year>=1991&year<2000&high1==0;
	scalar mean=r(mean);
	scalar sd=r(sd);
	putexcel I`t'=(`=mean') J`t'=(`=sd'), nformat(`z') hcenter;
};

*******************************************************************************;
*Appendix Table 3: Cross-Province Migration;
*******************************************************************************;
*See the do file: "appendix table 3.do"

*******************************************************************************;
*Appendix Table 4: Hospitals and Barangay Health Stations Over Time;
*******************************************************************************;
*See 2012 Philippine Statistical Yearbook;

*******************************************************************************;
*Appendix Table 5: Results by Gender
*Appendix Figure 4: By Gender;
*******************************************************************************;

#delimit ;

foreach var of varlist enroll_f1 enroll_m1  {;
	
	if "`var'"=="enroll_f1" {; local t="1"; };
	if "`var'"=="enroll_m1" {; local t="2"; };
	
	if "`var'"=="enroll_f1" {; local w="1991"; };
	if "`var'"=="enroll_m1" {; local w="1991"; };

	if "`var'"=="enroll_f1" {; local v="ylabel(0(1)4) ymtick(0(.5)4)"; };
	if "`var'"=="enroll_m1" {; local v="ylabel(0(1)4) ymtick(0(.5)4)"; };

	if "`var'"=="enroll_f1" {; local c="Percentage Points"; };
	if "`var'"=="enroll_m1" {; local c="Percentage Points"; };

	*POOLED;
	xi: reg `var' post2000_high post2000_trend post2007_high post2007_trend ttrend_high1 yr1991 yr1992 yr1993 yr1994 yr1995 yr1996 yr1997 yr1998 yr2000 yr2001 yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010 yr2011 yr2012 yr2013 i.provcode $controls_yr if year>=`w'&year<=2013,cluster(province); 
	estimates store spec`t', title("`var'");
	su `var' if e(sample)&year<2000&high1==1;
	scalar dep_mean=r(mean);
	estadd scalar dep_mean=dep_mean;

	preserve;
	
	gen slope1991=-8*_b[ttrend_high1];
	forvalues x=1992/1998 {;
		local i=`x'-1999;
		gen slope`x'=`i'*_b[ttrend_high1];
	};

	gen slope1999=0*_b[ttrend_high1];

	forvalues x=2000/2006 {;
		local i=`x'-1999;
		local j=`x'-2000;

		gen slope`x'=`i'*_b[ttrend_high1]+_b[post2000_high]+`j'*_b[post2000_trend];
	};

	gen slope2007=8*_b[ttrend_high1]+_b[post2000_high]+7*_b[post2000_trend]+0*_b[post2007_trend]+_b[post2007_high];


	forvalues x=2008/2013 {;
		local i=`x'-1999;
		local j=`x'-2006;
		local k=`x'-2000;
		local m=`x'-2007;

		gen slope`x'=`i'*_b[ttrend_high1]+_b[post2000_high]+_b[post2007_high]+`k'*_b[post2000_trend]+`m'*_b[post2007_trend];

	};

	*EVENT STUDY VERSION;
	char year[omit]1999;
	xi: reg `var'  i.year|high1 i.year i.provcode $controls_yr if year>=`w'&year<=2013 , cluster(province) noomit;
	estimates store event`t', title('var');
	test _IyeaXhig_1992 _IyeaXhig_1993 _IyeaXhig_1994 _IyeaXhig_1995 _IyeaXhig_1996 _IyeaXhig_1997 _IyeaXhig_1998; 		
	sum `var' if high1==1 & year==2000;
	local mean=`r(mean)';
				
	foreach y of numlist 1991(1)1998 2000(1)2013 {;
			gen b_`y' = _b[_IyeaXhig_`y'];
			gen upper_`y' = b_`y' + ( _se[_IyeaXhig_`y'] * 1.96 );
			gen lower_`y' = b_`y' - ( _se[_IyeaXhig_`y'] * 1.96 );
	};

		gen b_1999=0;
		replace b_1997=.;
		replace upper_1997=.;
		replace lower_1997=.;
		
		keep b_* upper_* lower_* slope*;
		
		
		collapse b_* upper_* lower_* slope*; 
		
		gen temp=1;
		reshape long b_ upper_ lower_ slope, i(temp) j(year); 
		drop temp;
		
		drop if year<`w';
		
		twoway (line b_ year, lcolor(black) lpattern(solid))
				(line upper_  year, lcolor(black) lpattern(dot))
				(line lower_ year, lcolor(black) lpattern(dot))
				(line slope year, lcolor(black) lpattern(dash)),

				legend(off)
				xtitle("Year") 
				yline(0, lstyle(shortdash_dot)) ylab(, nogrid) ytitle(`c')
				plotregion(fcolor(white)) graphregion(fcolor(white))
				xline(2000 2007, lpattern(solid) lcolor(gs14))
				`v';
				
		graph export "${output}Main Figures/EventStudy_`var'.pdf", replace;

		
restore;	
};

*Graduation by gender;
foreach var of varlist grad_m1 grad_f1 {;
	
	if "`var'"=="grad_m1" {; local t="3"; };
	if "`var'"=="grad_f1" {; local t="4"; };

	if "`var'"=="grad_f1" {; local w="1998"; };
	if "`var'"=="grad_m1" {; local w="1998"; };
	
	if "`var'"=="grad_f1" {; local v="ylabel(-1(1)1) ymtick(-1(.5)1)"; };
	if "`var'"=="grad_m1" {; local v="ylabel(-1(1)1) ymtick(-1(.5)1)"; };
	
	if "`var'"=="grad_f1" {; local c="Percentage Points"; };
	if "`var'"=="grad_m1" {; local c="Percentage Points"; };


	*POOLED;
	xi: reg `var' post2003_high post2003_trend_three post2010_high post2010_trend_three ttrend_three_high1 yr1991 yr1992 yr1993 yr1994 yr1995 yr1996 yr1997 yr1998 yr2000 yr2001 
		yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010 yr2011 yr2012 yr2013 i.provcode $controls_yr if year>=`w'&year<=2013, cluster(province); 
	
	estimates store spec`t', title("`var'");
	su `var' if e(sample)&year>=1998&year<2003&high1==1;
	scalar dep_mean=r(mean);
	estadd scalar dep_mean=dep_mean;
	
	preserve;
	gen slope1991=-11*_b[ttrend_three_high1];
	forvalues x=1992/2001 {;
		local i=`x'-2002;
		gen slope`x'=`i'*_b[ttrend_three_high1];
	};
	
	
	gen slope2002=0*_b[ttrend_three_high1];
	
	forvalues x=2003/2009 {;
		local i=`x'-2002;
		local j=`x'-2003;

		gen slope`x'=`i'*_b[ttrend_three_high1]+_b[post2003_high]+`j'*_b[post2003_trend_three];
	};

	gen slope2010=8*_b[ttrend_three_high1]+_b[post2003_high]+7*_b[post2003_trend_three]+0*_b[post2010_trend_three]+_b[post2010_high];


	forvalues x=2011/2013 {;
		local i=`x'-2002;
		local j=`x'-2009;
		local k=`x'-2003;
		local m=`x'-2010;

		gen slope`x'=`i'*_b[ttrend_three_high1]+_b[post2003_high]+_b[post2010_high]+`k'*_b[post2003_trend_three]+`m'*_b[post2010_trend_three];

	};
	
	*EVENT STUDY VERSION;
	char year[omit]2002;
	xi: reg `var'  i.year|high1 i.year i.provcode $controls_yr if year>=1998&year<=2013, cluster(province) noomit;
	estimates store event`t', title('var');
	test _IyeaXhig_1998 _IyeaXhig_2000 _IyeaXhig_2001;
	sum `var' if high1==1 & year==2000;
	local mean=`r(mean)';
				
	foreach y of numlist 1991(1)2001 2003(1)2013 {;
			gen b_`y' = _b[_IyeaXhig_`y'];
			gen upper_`y' = b_`y' + ( _se[_IyeaXhig_`y'] * 1.96 );
			gen lower_`y' = b_`y' - ( _se[_IyeaXhig_`y'] * 1.96 );
	};

		gen b_2002=0;
		
		keep b_* upper_* lower_* slope*;
		
		
		collapse b_* upper_* lower_* slope*; 
		
		gen temp=1;
		reshape long b_ upper_ lower_ slope, i(temp) j(year); 
		drop temp;
		
		drop if year<`w';
		
		twoway (line b_ year, lcolor(black) lpattern(solid))
				(line upper_  year, lcolor(black) lpattern(dot))
				(line lower_ year, lcolor(black) lpattern(dot))
				(line slope year, lcolor(black) lpattern(dash)),

				legend(off)
				xtitle("Year") 
				yline(0, lstyle(shortdash_dot)) ylab(, nogrid) ytitle(`c')
				plotregion(fcolor(white)) graphregion(fcolor(white))
				xline(2000 2007, lpattern(solid) lcolor(gs14)) 
				xlabel(1990(5)2015) ymtick(1990(5)2015) `v';
				
		graph export "${output}Main Figures/EventStudy_4y_`var'.pdf", replace;

		
restore;	
};

*Output Appendix Table 5;
	estout spec1 spec2 using "${output}Table_gender.txt", 
		replace 
		cells(b(star fmt(%9.3f)) se(par)) 
		starlevels(* 0.10 ** 0.05 *** 0.01)
		stats(N r2 dep_mean post6coef post6se post6p con6coef con6se con6p
			, fmt(0 3 3) labels("N" "R2" "Mean Dependent Variable"))
		keep(post2000_high post2000_trend post2007_high post2007_trend ttrend_high1)
		order(post2000_high post2000_trend post2007_high post2007_trend ttrend_high1)
		label;

	estout spec3 spec4 using "${output}Table_gender.txt", 
		append
		cells(b(star fmt(%9.3f)) se(par)) 
		starlevels(* 0.10 ** 0.05 *** 0.01)
		stats(N r2 dep_mean post6coef post6se post6p con6coef con6se con6p
			, fmt(0 3 3) labels("N" "R2" "Mean Dependent Variable"))		
		keep(post2003_high post2003_trend_three post2010_high post2010_trend_three ttrend_three_high1)
		order(post2003_high post2003_trend_three post2010_high post2010_trend_three ttrend_three_high1)
		label;
		
**********************************************************************;
*Test if male and female results are significantly different;
*ENROLLMENT;
#delimit ;
char year[omit]1999;
xi: reg enroll_f1  i.year|high1 i.year i.provcode $controls_yr if year>=1991&year<=2013 , noomit;
estimates store a1;
xi: reg enroll_m1  i.year|high1 i.year i.provcode $controls_yr if year>=1991&year<=2013 , noomit;
estimates store a2;
suest a1 a2, vce(cluster province);

#delimit ;
testnl (([a1_mean]_b[_IyeaXhig_2000]
	+[a1_mean]_b[_IyeaXhig_2001]
	+[a1_mean]_b[_IyeaXhig_2002]
	+[a1_mean]_b[_IyeaXhig_2003]
	+[a1_mean]_b[_IyeaXhig_2004]
	+[a1_mean]_b[_IyeaXhig_2005]
	+[a1_mean]_b[_IyeaXhig_2006]
	)/7)/.926
	=(([a2_mean]_b[_IyeaXhig_2000]
	+[a2_mean]_b[_IyeaXhig_2001]
	+[a2_mean]_b[_IyeaXhig_2002]
	+[a2_mean]_b[_IyeaXhig_2003]
	+[a2_mean]_b[_IyeaXhig_2004]
	+[a2_mean]_b[_IyeaXhig_2005]
	+[a2_mean]_b[_IyeaXhig_2006]
	)/7)/.271;
	
*GRADUATION;
#delimit ;
char year[omit]1999;
xi: reg grad_f1  i.year|high1 i.year i.provcode $controls_yr if year>=1991&year<=2013 , noomit;
estimates store a1;
xi: reg grad_m1  i.year|high1 i.year i.provcode $controls_yr if year>=1991&year<=2013 , noomit;
estimates store a2;
suest a1 a2, vce(cluster province);

#delimit ;
testnl (([a1_mean]_b[_IyeaXhig_2003]
	+[a1_mean]_b[_IyeaXhig_2004]
	+[a1_mean]_b[_IyeaXhig_2005]
	+[a1_mean]_b[_IyeaXhig_2006]
	+[a1_mean]_b[_IyeaXhig_2007]
	+[a1_mean]_b[_IyeaXhig_2008]
	+[a1_mean]_b[_IyeaXhig_2009]
	)/7)/.108
	=(([a2_mean]_b[_IyeaXhig_2003]
	+[a2_mean]_b[_IyeaXhig_2004]
	+[a2_mean]_b[_IyeaXhig_2005]
	+[a2_mean]_b[_IyeaXhig_2006]
	+[a2_mean]_b[_IyeaXhig_2007]
	+[a2_mean]_b[_IyeaXhig_2008]
	+[a2_mean]_b[_IyeaXhig_2009]
	)/7)/.025;

	
********************************************************************************;
*Appendix Table 6: Nursing Licensure Exam Pass Rates;
********************************************************************************;
	*Create Excel Sheet for Tables;
	putexcel set "${output}/Final Tables", modify sheet("Pass Rates");
	*Add labels;
	putexcel A1 = ("Appendix Table6. Effect on Pass Rates"), border("bottom"); 
	putexcel B2 = ("Passers out of Population") C2 = ("Examinees out of Population") 
		D2 = ("Implied Pass Rate (Column 1/Column 2)") E2 = ("P-value on test of equality with pre-period pass rate (0.58)"), hcenter txtwrap; 
	putexcel A3= ("Year") ;
	putexcel B3 = ("(1)") C3 = ("(2)") D3 = ("(3)") E3 = ("4"), hcenter; 
	putexcel A3= ("Year") B3 = ("(1)") C3 = ("(2)") D3 = ("(3)") E3 = ("4"), border("bottom");  
	putexcel A4=("Average Effect (2000-2013)");
	local i=2000;
	forvalues x=6(2)32 {;
		putexcel A`x' = ("`i'");
		local i =`i'+1;
	};

	*AVERAGE EFFECT;
	char year[omit]1999;
	xi: reg pass_rate_grad post2000_high i.year i.provcode $controls_yr if year>=1991&year<=2013 , noomit cl(province);
			putexcel B5 = _se[post2000_high], nformat("(0.000)") hcenter;
			local t = _b[post2000_high]/_se[post2000_high];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2000_high];
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel B4 = "`coefstar'", hcenter;
			drop pval_1 s_1;
			gen pass_a = _b[post2000_high];
			
	xi: reg examinee_rate_grad  post2000_high i.year i.provcode $controls_yr if year>=1991&year<=2013 , noomit cl(province);
			putexcel C5 = _se[post2000_high], nformat("(0.000)") hcenter;
			local t = _b[post2000_high]/_se[post2000_high];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2000_high];
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel C4 = "`coefstar'", hcenter;
			drop pval_1 s_1;
			gen exam_a = _b[post2000_high];
			
			*Divide coefficients from Column 1 and 2;
			gen pass_exam_a=pass_a/exam_a;
			putexcel D4 = pass_exam_a, nformat("0.000") hcenter;
			
			drop pass_a exam_a pass_exam_a;
			
			
	*Use suest to get p-value testing for equality with pass rate in pre-period;
	char year[omit]1999;
	xi: reg pass_rate_grad post2000_high i.year i.provcode $controls_yr if year>=1991&year<=2013 , noomit;
	estimates store a1;
	xi: reg examinee_rate post2000_high i.year i.provcode $controls_yr if year>=1991&year<=2013 ,  noomit;
	estimates store a2;
	suest a1 a2, vce(cluster province);

	testnl (([a1_mean]_b[post2000_high])/([a2_mean]_b[post2000_high])=.5778252);
		gen pval=r(p);
		putexcel E4=pval, hcenter nformat("0.000");
		drop pval;


	* EFFECTS BY INDIVIDUAL YEARS;
	char year[omit]1999;
	local i_coeff=6;
	local j_se=7; 
	forvalues x=2000/2013 {;
		xi: reg pass_rate_grad  i.year|high1 i.year i.provcode $controls_yr if year>=1991&year<=2013 , noomit cl(province);
			test _IyeaXhig_1992 _IyeaXhig_1993 _IyeaXhig_1994 _IyeaXhig_1995 _IyeaXhig_1996 _IyeaXhig_1997 _IyeaXhig_1998;
			putexcel B`j_se' = _se[_IyeaXhig_`x'], nformat("(0.000)") hcenter;
			local t = _b[_IyeaXhig_`x']/_se[_IyeaXhig_`x'];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[_IyeaXhig_`x'];
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel B`i_coeff' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			gen pass_`x' = _b[_IyeaXhig_`x'];
			
		*EXAMINEE_RATE_POP;	
		xi: reg examinee_rate_grad i.year|high1 i.year i.provcode $controls_yr if year>=1991&year<=2013 ,  noomit cl(province);
			putexcel C`j_se' = _se[_IyeaXhig_`x'], nformat("(0.000)") hcenter;
			local t = _b[_IyeaXhig_`x']/_se[_IyeaXhig_`x'];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[_IyeaXhig_`x'];
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel C`i_coeff' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			gen exam_`x' = _b[_IyeaXhig_`x'];
			
			*Divide coefficients from Column 1 and 2;
			gen pass_exam_`x'=pass_`x'/exam_`x';
			putexcel D`i_coeff' = pass_exam_`x', nformat("0.000") hcenter;
			
			drop pass_2* exam_2* pass_exam_2*;

			local i_coeff=`i_coeff'+2;
			local j_se=`j_se'+2; 
	};

	*Now use suest to get p-value testing for equality with pass rate in pre-period;
	#delimit ;
	char year[omit]1999;
	xi: reg pass_rate_grad i.year|high1 i.year i.provcode $controls_yr if year>=1991&year<=2013 , noomit;
	estimates store m1;
	xi: reg examinee_rate_grad i.year|high1 i.year i.provcode $controls_yr if year>=1991&year<=2013 ,  noomit;
	estimates store m2;
	suest m1 m2, vce(cluster province);

	#delimit ;
	local i=6;
	forvalues x=2000/2013 {;
		disp "This loop is for `x'";
		*Test equivalence to pre-2000 average pass rate;
		disp "Pre-2000";
		testnl (([m1_mean]_b[_IyeaXhig_`x'])/([m2_mean]_b[_IyeaXhig_`x'])=0.5778252);
		gen pval=r(p);
		putexcel E`i'=pval, hcenter nformat("0.000");
		drop pval;
		local i = `i'+2;
	};

********************************************************************************;
*Appendix Table 7: Robustness Checks;
********************************************************************************;
*Create interactions for continuous case;
gen post2000_high_c=post2000*premigrate1990;
gen post2007_high_c=post2007*premigrate1990;

gen post2003_high_c=post2003*premigrate1990;
gen post2010_high_c=post2010*premigrate1990;

putexcel set "${output}/Final Tables", modify sheet("AT7");
*Add labels;
putexcel A1:F1 = ("Appendix Table 7. Robustness Checks of Effect of Demand for Nurse Migrants on Nursing Education Outcomes"), border("bottom") merge; 
putexcel B2 = ("Nurse Migration Rate") C2 = ("Nurse Enrollment") 
	D2 = ("Nurse Graduation") E2 = ("Nurse Programs") F2 = ("Total Graduation"), hcenter txtwrap; 
	
putexcel A4=("Panel A. Main specification"), italic underline;
putexcel A9=("Panel B. Plus baseline non-nurse migration rate x year fixed effects"), italic underline;
putexcel A14=("Panel C. Without Manila"), italic underline;
putexcel A19=("Panel D. Plus additional controls x year fixed effects"), italic underline;
putexcel A24=("Panel E. Plus additional controls x year fixed effects, without Manila"), italic underline;
putexcel A29=("Panel F. Plus island x year fixed effects"), italic underline;
putexcel A34=("Panel G. Continuous Treatment Measure: Baseline Nurse Migration Rate"), italic underline;

putexcel B3=("(1)") C3=("(2)")  D3=("(3)")  E3=("(4)") F3=("(5)"), hcenter border("bottom");

local i=2;
forvalues x=5(5)39 {;
	putexcel A`x'=("Post Expansion");
	local j =`i'+`x';
	putexcel A`j'=("Post Contraction");
};

*PANELS A, B, D, F;
foreach var of varlist migrateUSA_hth enroll_tot1 nurseprog {;
		
		if "`var'"=="migrateUSA_hth" {; local c="B"; };
		if "`var'"=="enroll_tot1" {; local c="C"; };
		if "`var'"=="nurseprog" {; local c="E"; };
		if "`var'"=="enroll_tot" {; local c="H"; };
		if "`var'"=="enroll_tot0" {; local c="I"; };
		if "`var'"=="grad_tot0" {; local c="G"; };


		if "`var'"=="migrateUSA_hth" {; local w="1991"; };
		if "`var'"=="enroll_tot1" {; local w="1991"; };
		if "`var'"=="nurseprog" {; local w="1991"; };
		if "`var'"=="enroll_tot" {; local w="1991"; };
		if "`var'"=="enroll_tot0" {; local w="1991"; };
		if "`var'"=="grad_tot0" {; local w="1998"; };
	
		foreach check in "$controls_yr"
				 "$controls_yr migrate_nonnurse_yr*"
				 "$controls_yr_full"
				 "$controls_yr island_x*"  {;
				 
			if "`check'"=="$controls_yr" {; local r="5"; };
			if "`check'"=="$controls_yr migrate_nonnurse_yr*" {; local r="10"; };
			if "`check'"=="$controls_yr_full" {; local r="20"; };
			if "`check'"=="$controls_yr island_x*" {; local r="30"; };

			local i_b00=`r';
			local i_se00=`i_b00'+1;
			local i_b07=`i_b00'+2;
			local i_se07=`i_b00'+3;	

		xi: reg `var' post2000_high post2007_high yr1991 yr1992 yr1993 yr1994 yr1995 yr1996 yr1997 yr1998 yr2000 yr2001 
			yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010 yr2011 yr2012 yr2013 i.provcode 
			`check' if year>=`w'&year<=2013, cluster(province); 
			
			putexcel `c'`i_se00' = _se[post2000_high], nformat("(0.000)") hcenter;
			local t = _b[post2000_high]/_se[post2000_high];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2000_high];
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel `c'`i_b00' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
			putexcel `c'`i_se07' = _se[post2007_high], nformat("(0.000)") hcenter;
			local t = _b[post2007_high]/_se[post2007_high];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2007_high];
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel `c'`i_b07' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
		};
		
};

*No Manila;
foreach var of varlist migrateUSA_hth enroll_tot1 nurseprog {;
		
		if "`var'"=="migrateUSA_hth" {; local c="B"; };
		if "`var'"=="enroll_tot1" {; local c="C"; };
		if "`var'"=="nurseprog" {; local c="E"; };
		if "`var'"=="enroll_tot" {; local c="H"; };
		if "`var'"=="enroll_tot0" {; local c="I"; };
		if "`var'"=="grad_tot0" {; local c="G"; };


		if "`var'"=="migrateUSA_hth" {; local w="1991"; };
		if "`var'"=="enroll_tot1" {; local w="1991"; };
		if "`var'"=="nurseprog" {; local w="1991"; };
		if "`var'"=="enroll_tot" {; local w="1991"; };
		if "`var'"=="enroll_tot0" {; local w="1991"; };
		if "`var'"=="grad_tot0" {; local w="1998"; };
		
		
		foreach check in 	"$controls_yr_full"
							"$controls_yr"
				 
		{;
		
			if "`check'"=="$controls_yr_full" {; local r="25"; };
			if "`check'"=="$controls_yr" {; local r="15"; };
		
			local i_b00=`r';
			local i_se00=`i_b00'+1;
			local i_b07=`i_b00'+2;
			local i_se07=`i_b00'+3;	

		*BASIC DID;
		xi: reg `var' post2000_high post2007_high yr1991 yr1992 yr1993 yr1994 yr1995 yr1996 yr1997 yr1998 yr2000 yr2001 
			yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010 yr2011 yr2012 yr2013 i.provcode 
			`check' if year>=`w'&year<=2013&province!="THIRD DISTRICT", cluster(province); 
			
			putexcel `c'`i_se00' = _se[post2000_high], nformat("(0.000)") hcenter;
			local t = _b[post2000_high]/_se[post2000_high];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2000_high];
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel `c'`i_b00' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
			putexcel `c'`i_se07' = _se[post2007_high], nformat("(0.000)") hcenter;
			local t = _b[post2007_high]/_se[post2007_high];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2007_high];
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel `c'`i_b07' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
		};
		
};


*Panel G: Continuous;

foreach var of varlist migrateUSA_hth enroll_tot1 nurseprog {;
		
		if "`var'"=="migrateUSA_hth" {; local c="B"; };
		if "`var'"=="enroll_tot1" {; local c="C"; };
		if "`var'"=="nurseprog" {; local c="E"; };

		if "`var'"=="migrateUSA_hth" {; local w="1991"; };
		if "`var'"=="enroll_tot1" {; local w="1991"; };
		if "`var'"=="nurseprog" {; local w="1991"; };
		
		foreach check in 	"$controls_yr"
				 
		{;
		
			if "`check'"=="$controls_yr" {; local r="35"; };
			
			local i_b00=`r';
			local i_se00=`i_b00'+1;
			local i_b07=`i_b00'+2;
			local i_se07=`i_b00'+3;	

		*BASIC DID;
		xi: reg `var' post2000_high_c post2007_high_c yr1991 yr1992 yr1993 yr1994 yr1995 yr1996 yr1997 yr1998 yr2000 yr2001 
			yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010 yr2011 yr2012 yr2013 i.provcode 
			`check' if year>=`w'&year<=2013, cluster(province); 
			
			putexcel `c'`i_se00' = _se[post2000_high]*.0026469, nformat("(0.000)") hcenter;
			local t = _b[post2000_high]/_se[post2000_high];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2000_high]*.0026469 ;
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel `c'`i_b00' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
			putexcel `c'`i_se07' = _se[post2007_high]*.0026469 , nformat("(0.000)") hcenter;
			local t = _b[post2007_high]/_se[post2007_high];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2007_high]*.0026469 ;
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel `c'`i_b07' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
		};
		
};


*Columns 3 and 5 of Appendix Table 7;
*Panels A, B, D, F;

foreach var of varlist grad_tot1 grad_tot {;
		
		if "`var'"=="grad_tot1" {; local c="D"; };
		if "`var'"=="grad_tot" {; local c="F"; };

		if "`var'"=="grad_tot1" {; local w="1998"; };
		if "`var'"=="grad_tot" {; local w="1998"; };

		
		foreach check in "$controls_yr"
				 "$controls_yr migrate_nonnurse_yr*"
				 "$controls_yr_full"
				 "$controls_yr island_x*"
	
			{;
			
			if "`check'"=="$controls_yr" {; local r="5"; };
			if "`check'"=="$controls_yr migrate_nonnurse_yr*" {; local r="10"; };
			if "`check'"=="$controls_yr_full" {; local r="20"; };
			if "`check'"=="$controls_yr island_x*" {; local r="30"; };
			
			local i_b04=`r';
			local i_se04=`i_b04'+1;
			local i_b11=`i_b04'+2;
			local i_se11=`i_b04'+3;	

		*BASIC DID;
		xi: reg `var' post2003_high post2010_high yr1991 yr1992 yr1993 yr1994 yr1995 yr1996 yr1997 yr1998 yr2000 yr2001 
			yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010 yr2011 yr2012 yr2013 i.provcode 
			`check' if year>=`w'&year<=2013, cluster(province); 
			
			putexcel `c'`i_se04' = _se[post2003_high], nformat("(0.000)") hcenter;
			local t = _b[post2003_high]/_se[post2003_high];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2003_high];
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel `c'`i_b04' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
			putexcel `c'`i_se11' = _se[post2010_high], nformat("(0.000)") hcenter;
			local t = _b[post2010_high]/_se[post2010_high];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2010_high];
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel `c'`i_b11' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
		};
};

*Panels C and E;
foreach var of varlist grad_tot1 grad_tot {;
		
		if "`var'"=="grad_tot1" {; local c="D"; };
		if "`var'"=="grad_tot" {; local c="F"; };

		if "`var'"=="grad_tot1" {; local w="1998"; };
		if "`var'"=="grad_tot" {; local w="1998"; };
	
		foreach check in "$controls_yr_full"
							"$controls_yr"
				 
{;
			if "`check'"=="$controls_yr_full" {; local r="25"; };
			if "`check'"=="$controls_yr" {; local r="15"; };
		
			local i_b04=`r';
			local i_se04=`i_b04'+1;
			local i_b11=`i_b04'+2;
			local i_se11=`i_b04'+3;	

		*BASIC DID;
		xi: reg `var' post2003_high post2010_high yr1991 yr1992 yr1993 yr1994 yr1995 yr1996 yr1997 yr1998 yr2000 yr2001 
			yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010 yr2011 yr2012 yr2013 i.provcode 
			`check' if year>=`w'&year<=2013&province!="THIRD DISTRICT", cluster(province); 
			
			putexcel `c'`i_se04' = _se[post2003_high], nformat("(0.000)") hcenter;
			local t = _b[post2003_high]/_se[post2003_high];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2003_high];
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel `c'`i_b04' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
			putexcel `c'`i_se11' = _se[post2010_high], nformat("(0.000)") hcenter;
			local t = _b[post2010_high]/_se[post2010_high];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2010_high];
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel `c'`i_b11' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
		};
};

*Panel G;
foreach var of varlist grad_tot1 grad_tot {;
		
		if "`var'"=="grad_tot1" {; local c="D"; };
		if "`var'"=="grad_tot" {; local c="F"; };

		if "`var'"=="grad_tot1" {; local w="1998"; };
		if "`var'"=="grad_tot" {; local w="1998"; };
		
		foreach check in "$controls_yr"
				 
{;
			if "`check'"=="$controls_yr" {; local r="35"; };
			
			local i_b04=`r';
			local i_se04=`i_b04'+1;
			local i_b11=`i_b04'+2;
			local i_se11=`i_b04'+3;	

		*BASIC DID;
		xi: reg `var' post2003_high_c post2010_high_c yr1991 yr1992 yr1993 yr1994 yr1995 yr1996 yr1997 yr1998 yr2000 yr2001 
			yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010 yr2011 yr2012 yr2013 i.provcode 
			`check' if year>=`w'&year<=2013, cluster(province); 
			
			putexcel `c'`i_se04' = _se[post2003_high]*.0026469, nformat("(0.000)") hcenter;
			local t = _b[post2003_high]/_se[post2003_high];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2003_high]*.0026469;
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel `c'`i_b04' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
			putexcel `c'`i_se11' = _se[post2010_high]*.0026469, nformat("(0.000)") hcenter;
			local t = _b[post2010_high]/_se[post2010_high];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2010_high]*.0026469;
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel `c'`i_b11' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
		};
};

*********************************************************;
*APPENDIX Table 8: Pooled robustness estimates;
*Panels A, B, D, F;
*********************************************************;
#delimit ;
foreach check in "$controls_yr"
				 "$controls_yr_full"
				 "$controls_yr migrate_nonnurse_yr*"
				 "$controls_yr island_x_time*" 

{;
	if "`check'"=="$controls_yr_full" {; local r="main"; };
	if "`check'"=="$controls_yr_full" {; local r="full_controls"; };
	if "`check'"=="$controls_yr migrate_nonnurse_yr*"{; local r="basic_othermig"; };
	if "`check'"=="$controls_yr island_x_time*" {; local r="basic_islandxtime"; };

	if "`check'"=="$controls_yr" {; local d="1"; };
	if "`check'"=="$controls_yr_full" {; local d="4"; };
	if "`check'"=="$controls_yr migrate_nonnurse_yr*"{; local d="2"; };
	if "`check'"=="$controls_yr island_x_time*" {; local d="6"; };

	foreach var of varlist migrateUSA_hth enroll_tot1 nurseprog grad_tot {;
		
		if "`var'"=="migrateUSA_hth" {; local t="1"; };
		if "`var'"=="enroll_tot1" {; local t="2"; };
		if "`var'"=="nurseprog" {; local t="4"; };
		if "`var'"=="grad_tot" {; local t="5"; };

		if "`var'"=="migrateUSA_hth" {; local w="1991"; };
		if "`var'"=="enroll_tot1" {; local w="1991"; };
		if "`var'"=="nurseprog" {; local w="1991"; };
		if "`var'"=="grad_tot" {; local w="1998"; };

		*POOLED;
		xi: reg `var' post2000_high post2000_trend post2007_high post2007_trend ttrend_high1 yr1991 yr1992 yr1993 yr1994 yr1995 yr1996 yr1997 		yr1998 yr2000 yr2001 yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010 yr2011 yr2012 yr2013 i.provcode `check' if year>=`w'&		year<=2013, cluster(province); 
		
		estimates store spec`t'_`d', title("`var'");
		su `var' if e(sample)&year<2000;
		scalar dep_mean=r(mean);
		estadd scalar dep_mean=dep_mean;

		
	};
	
	*Graduation;
	foreach var of varlist grad_tot1 {;
		
		if "`var'"=="grad_tot1" {; local t="3"; };

		if "`var'"=="grad_tot1" {; local v="ylabel(-1(0.5)1) ymtick(-1(.25)1)"; };

		if "`var'"=="grad_tot1" {; local w="1998"; };

		if "`var'"=="grad_tot1" {; local c="Nurse Graduation Rate (%)"; };

		xi: reg `var' post2003_high post2003_trend_three post2010_high post2010_trend_three ttrend_three_high1 yr1991 yr1992 yr1993 yr1994 yr1995 		yr1996 yr1997 yr1998 yr2000 yr2001 yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010 yr2011 yr2012 yr2013 i.provcode `check' if 		year>=`w'&year<=2013, cluster(province); 
	
		estimates store spec`t'_`d', title("`var'");
		su `var' if e(sample)&year<2000;
		scalar dep_mean=r(mean);
		estadd scalar dep_mean=dep_mean;
		
	};
		
};

*******************************************;
*Panels C and E: Without Manila;
*******************************************;
#delimit ;
foreach check in "$controls_yr_full"
				 "$controls_yr" 

{;

	if "`check'"=="$controls_yr_full" {; local r="full_controls_nomnl"; };
	if "`check'"=="$controls_yr" {; local r="basic_nomnl"; };

	
	if "`check'"=="$controls_yr_full" {; local d="5"; };
	if "`check'"=="$controls_yr" {; local d="3"; };
	
	foreach var of varlist migrateUSA_hth enroll_tot1 nurseprog grad_tot {;
		
		if "`var'"=="migrateUSA_hth" {; local t="1"; };
		if "`var'"=="enroll_tot1" {; local t="2"; };
		if "`var'"=="nurseprog" {; local t="4"; };
		if "`var'"=="grad_tot" {; local t="5"; };

		if "`var'"=="migrateUSA_hth" {; local w="1991"; };
		if "`var'"=="enroll_tot1" {; local w="1991"; };
		if "`var'"=="nurseprog" {; local w="1991"; };
		
		*POOLED;
		xi: reg `var' post2000_high post2000_trend post2007_high post2007_trend ttrend_high1 yr1991 yr1992 yr1993 yr1994 yr1995 yr1996 yr1997 yr1998 yr2000 yr2001 yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010 yr2011 yr2012 yr2013 i.provcode `check' if year>=`w'&year<=2013&province!="THIRD DISTRICT", cluster(province); 
		estimates store spec`t'_`d', title("`var'");
		su `var' if e(sample)&year<2000;
		scalar dep_mean=r(mean);
		estadd scalar dep_mean=dep_mean;

		
	};
	
	*Graduation;
	foreach var of varlist grad_tot1 {;
		
		if "`var'"=="grad_tot1" {; local t="3"; };

		if "`var'"=="grad_tot1" {; local w="1998"; };

		xi: reg `var' post2003_high post2003_trend_three post2010_high post2010_trend_three ttrend_three_high1 yr1991 yr1992 yr1993 yr1994 yr1995 yr1996 yr1997 yr1998 yr2000 yr2001 
		yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010 yr2011 yr2012 yr2013 i.provcode `check' if year>=`w'&year<=2013&province!="THIRD DISTRICT", cluster(province); 
	
		estimates store spec`t'_`d', title("`var'");
		su `var' if e(sample)&year<2000;
		scalar dep_mean=r(mean);
		estadd scalar dep_mean=dep_mean;
		
	};
};

*Create interactions for continuous case;

gen post2000_trend_c=post2000_high_c*(ttrend-1);
gen post2007_trend_c=post2007_high_c*(ttrend-1);
replace post2007_trend_c=post2007_trend_c-7 if post2007_trend_c!=0; 
gen ttrend_high1_c=ttrend*premigrate1990;

gen post2003_trend_three_c=post2003_high_c*(ttrend_three-1);
gen post2010_trend_three_c=post2010_high_c*(ttrend_three-1);
replace post2010_trend_three_c=post2010_trend_three_c-7 if post2010_trend_three_c!=0; 
gen ttrend_three_high1_c=ttrend_three*premigrate1990;

#delimit ;
putexcel set "${output}/Final Tables", modify sheet("Robustness_pooled");
*Add labels;
putexcel A1:E1 = ("Appendix Table 7. Robustness Checks of Effect of Demand for Nurse Migrants on Nursing Education Outcomes:LRS"), border("bottom") merge; 
putexcel B2 = ("Nurse Migration Rate") C2 = ("Nurse Enrollment") 
	D2 = ("Nurse Graduation") E2 = ("Nurse Programs") F2 = ("Total Graduation"), hcenter txtwrap; 
	
	
putexcel A4=("Continuous"), italic underline;

putexcel B3=("(1)") C3=("(2)")  D3=("(3)")  E3=("(4)") F3=("(5)"), hcenter border("bottom");


local i_b00=5;
local i_se00=`i_b00'+1;
local i_b00_t=`i_b00'+2;
local i_se00_t=`i_b00'+3;
local i_b07=`i_b00'+4;
local i_se07=`i_b00'+5;	
local i_b07_t=`i_b00'+6;
local i_se07_t=`i_b00'+7;	
local i_btt=`i_b00'+8;
local i_sett=`i_b00'+9;

#delimit ;
foreach var of varlist migrateUSA_hth enroll_tot1 nurseprog grad_tot {;
		
		if "`var'"=="migrateUSA_hth" {; local t="1"; };
		if "`var'"=="enroll_tot1" {; local t="2"; };
		if "`var'"=="nurseprog" {; local t="4"; };
		if "`var'"=="grad_tot" {; local t="5"; };
		
		if "`var'"=="migrateUSA_hth" {; local c="B"; };
		if "`var'"=="enroll_tot1" {; local c="C"; };
		if "`var'"=="nurseprog" {; local c="E"; };
		if "`var'"=="grad_tot" {; local c="F"; };
	
	disp "This `var' is";
	xi: reg `var' post2000_high_c post2000_trend_c post2007_high_c post2007_trend_c ttrend_high1_c yr1991 yr1992 yr1993 yr1994 yr1995 yr1996 yr1997 yr1998 yr2000 yr2001 
			yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010 yr2011 yr2012 yr2013 i.provcode $controls_yr if year>=1991&year<=2013, cluster(province); 
		estimates store cont_`t', title("`var'");
		su `var' if e(sample)&year<2000;
		scalar dep_mean=r(mean);
		estadd scalar dep_mean=dep_mean;
		
			putexcel `c'`i_se00' = _se[post2000_high_c]*.0026469, nformat("(0.000)") hcenter;
			local t = _b[post2000_high_c]/_se[post2000_high_c];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2000_high_c]*.0026469 ;
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel `c'`i_b00' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
			putexcel `c'`i_se00_t' = _se[post2000_trend_c]*.0026469, nformat("(0.000)") hcenter;
			local t = _b[post2000_trend_c]/_se[post2000_trend_c];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2000_trend_c]*.0026469 ;
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel `c'`i_b00_t' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
			putexcel `c'`i_se07' = _se[post2007_high_c]*.0026469 , nformat("(0.000)") hcenter;
			local t = _b[post2007_high_c]/_se[post2007_high_c];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2007_high_c]*.0026469 ;
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel `c'`i_b07' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
			putexcel `c'`i_se07_t' = _se[post2007_trend_c]*.0026469 , nformat("(0.000)") hcenter;
			local t = _b[post2007_trend_c]/_se[post2007_trend_c];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2007_trend_c]*.0026469 ;
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel `c'`i_b07_t' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
			putexcel `c'`i_sett' = _se[ttrend_high1_c]*.0026469 , nformat("(0.000)") hcenter;
			local t = _b[ttrend_high1_c]/_se[ttrend_high1_c];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[ttrend_high1_c]*.0026469 ;
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel `c'`i_btt' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
};

*Nursing grad;
xi: reg grad_tot1 post2003_high_c post2003_trend_three_c post2010_high_c post2010_trend_three_c ttrend_three_high1_c yr1991 yr1992 yr1993 yr1994 yr1995 yr1996 yr1997 yr1998 yr2000 yr2001 
	yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010 yr2011 yr2012 yr2013 i.provcode $controls_yr if year>=1998&year<=2013, cluster(province); 
		estimates store cont_3, title("`var'");
		su grad_tot1 if e(sample)&year<2000;
		scalar dep_mean=r(mean);
		estadd scalar dep_mean=dep_mean;	
		
			putexcel D`i_se00' = _se[post2003_high_c]*.0026469, nformat("(0.000)") hcenter;
			local t = _b[post2003_high_c]/_se[post2003_high_c];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2003_high_c]*.0026469 ;
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel D`i_b00' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
			putexcel D`i_se00_t' = _se[post2003_trend_three_c]*.0026469, nformat("(0.000)") hcenter;
			local t = _b[post2003_trend_three_c]/_se[post2003_trend_three_c];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2003_trend_three_c]*.0026469 ;
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel D`i_b00_t' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
			putexcel D`i_se07' = _se[post2010_high_c]*.0026469 , nformat("(0.000)") hcenter;
			local t = _b[post2010_high_c]/_se[post2010_high_c];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2010_high_c]*.0026469 ;
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel D`i_b07' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
			putexcel D`i_se07_t' = _se[post2010_trend_three_c]*.0026469 , nformat("(0.000)") hcenter;
			local t = _b[post2010_trend_three_c]/_se[post2010_trend_three_c];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[post2010_trend_three_c]*.0026469 ;
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel D`i_b07_t' = "`coefstar'", hcenter;
			drop pval_1 s_1;
			
			putexcel D`i_sett' = _se[ttrend_three_high1_c]*.0026469 , nformat("(0.000)") hcenter;
			local t = _b[ttrend_three_high1_c]/_se[ttrend_three_high1_c];
			gen pval_1 = 2*ttail(e(df_r), abs(`t'));
			gen s_1 = "*" if pval_1 <0.1;
			replace s_1 = "**" if pval_1 <0.05;
			replace s_1 = "***" if pval_1 <0.01;
			local temp = _b[ttrend_three_high1_c]*.0026469 ;
			local stars = s_1[1];
			local coefstar: display %5.3f `macval(temp)' "`macval(stars)'";
			putexcel D`i_btt' = "`coefstar'", hcenter;
			drop pval_1 s_1;


			#delimit ;
*Output Results for Appendix Table 8;
	estout spec1_* using "${output}Table_slopes_robust.txt", 
		replace 
		cells(b(star fmt(%9.4f)) se(par)) 
		starlevels(* 0.10 ** 0.05 *** 0.01)
		stats(N r2 dep_mean, fmt(0 3 3) labels("N" "R2" "Mean Dependent Variable" "Grad Mean" "Nurse Mean"))
		keep(post2000_high post2000_trend post2007_high post2007_trend ttrend_high1)
		order(post2000_high post2000_trend post2007_high post2007_trend ttrend_high1)
		label;
		
	forvalues x=2/5 {;
	estout spec`x'_*  using "${output}Table_slopes_robust.txt", 
		append
		cells(b(star fmt(%9.3f)) se(par)) 
		starlevels(* 0.10 ** 0.05 *** 0.01)
		stats(N r2 dep_mean, fmt(0 3 3) labels("N" "R2" "Mean Dependent Variable"))
		keep(post2000_high post2000_trend post2007_high post2007_trend ttrend_high1)
		order(post2000_high post2000_trend post2007_high post2007_trend ttrend_high1)
		label;
	};
	
	estout spec3_*  using "${output}Table_slopes_robust.txt", 
		append
		cells(b(star fmt(%9.3f)) se(par)) 
		starlevels(* 0.10 ** 0.05 *** 0.01)
		stats(N r2 dep_mean, fmt(0 3 3) labels("N" "R2" "Mean Dependent Variable"))
		keep(post2003_high post2003_trend post2010_high post2010_trend ttrend_high1)
		order(post2003_high post2003_trend post2010_high post2010_trend ttrend_high1)
		label;
	};
	
	estout cont_3  using "${output}Table_slopes_robust_cont.txt", 
		replace
		cells(b(star fmt(%9.3f)) se(par)) 
		starlevels(* 0.10 ** 0.05 *** 0.01)
		stats(N r2 dep_mean, fmt(0 3 3) labels("N" "R2" "Mean Dependent Variable"))
		keep(post2003_high_c post2003_trend_three_c post2010_high_c post2010_trend_three_c ttrend_three_high1_c)
		order(post2003_high_c post2003_trend_three_c post2010_high_c post2010_trend_three_c ttrend_three_high1_c)
		label;
	
	
	estout cont_1 cont_2 cont_4 cont_5  using "${output}Table_slopes_robust_cont.txt", 
		append
		cells(b(star fmt(%9.3f)) se(par)) 
		starlevels(* 0.10 ** 0.05 *** 0.01)
		stats(N r2 dep_mean, fmt(0 3 3) labels("N" "R2" "Mean Dependent Variable"))
		keep(post2000_high_c post2000_trend_c post2007_high_c post2007_trend_c ttrend_high1_c)
		order(post2000_high_c post2000_trend_c post2007_high_c post2007_trend_c ttrend_high1_c)
		label;
	
estimates drop _all;

*************************************************************;
*APPENDIX TABLE 9;
*************************************************************;
*Calculations done based on equation 3 in appendix;

*************************************************************;
*APPENDIX FIGURE 1;
*************************************************************;

#delimit ;
use "${ched_data}analysis_sample.dta", clear ;

keep if year==1990;

gsort + migrateUSA_hth;
gen id=_n;
labmask id, values(province);

graph twoway (scatter migrateUSA_hth id, msymbol(circle) mcolor(black)), xtitle(Province) ytitle("Nurse Migrants per 100,000") 
	graphregion(color(white)) xline(37, lcolor(gs14)) xlabel(0 "0" 10 "10" 20 "20" 30 "30" 40 "40" 50 "50" 60 "60" 70 "70") 
	xmtick(0(1)74)
	ylabel(0(2)12) ymtick(0(1)12);
	
graph export "${output}Main Figures/AppendixFigure1.pdf", replace;


*************************************************************;
*APPENDIX FIGURE 2: Continous Treatment;
*************************************************************;
*See do file "appendix figure 2.do"

*************************************************************;
*APPENDIX FIGURE 3: Borusyak et al imputation estimator (2021);
*************************************************************;
*See do file "appendix figure 3.do"

*************************************************************;
*APPENDIX FIGURE 4: Results by Gender;
*************************************************************;
*See above;

*************************************************************;
*APPENDIX FIGURES 5 and 6;
*************************************************************;
*See do file "appendix figures 5 and 6.do"


*************************************************************;
*APPENDIX FIGURE 7;
*************************************************************;

#delimit ;

use "${ched_data}analysis_sample.dta", clear ;

xtset provcode year;

*SET CONTROLS;
global controls_yr emp_f_2564_90_yr* emp_m_2564_90_yr* female_90_yr* age_90_yr* nurse_cen_pc90_yr*;
global controls_yr_full emp_f_2564_90_yr* emp_m_2564_90_yr* female_90_yr* age_90_yr* nurse_cen_pc90_yr* _yrschl_2564_90_yr* urban_90_yr*  ;

gen migrate_othernurse=((nurse-nurseUSA)/totpop)*100;

gen migrate_othernurse_hth=((nurse-nurseUSA)/(totpop/100000));


foreach var of varlist migrate_othernurse_hth {;
	
	if "`var'"=="migrate_othernurse_hth" {; local t="1"; };

	char year[omit]1999;
	xi: reg `var'  i.year|high1 i.year i.provcode $controls_yr if year>=1991&year<=2013 , cluster(province) noomit;
	estimates store event`t', title('var');
	test _IyeaXhig_1992 _IyeaXhig_1993 _IyeaXhig_1994 _IyeaXhig_1995 _IyeaXhig_1996 _IyeaXhig_1997 _IyeaXhig_1998; 	
	estadd scalar pretrend=r(p);

	sum `var' if high1==1 & year==2000;
	local mean=`r(mean)';
	
	
	foreach y of numlist 1991(1)1998 2000(1)2013 {;
			gen b_`y' = _b[_IyeaXhig_`y'];
			gen upper_`y' = b_`y' + ( _se[_IyeaXhig_`y'] * 1.96 );
			gen lower_`y' = b_`y' - ( _se[_IyeaXhig_`y'] * 1.96 );
	};

		gen b_1999=0;
		keep b_* upper_* lower_*;
		
		
		collapse b_* upper_* lower_*; 
		
		gen temp=1;
		reshape long b_ upper_ lower_, i(temp) j(year); 
		drop temp;
		
		drop if year<1991;
		
				twoway (line b_ year, lcolor(black) lpattern(solid))
				(line upper_  year, lcolor(black) lpattern(dot))
				(line lower_ year, lcolor(black) lpattern(dot)),
				legend(off)
				xtitle("Year") ytitle("Percentage Points")
				yline(0, lstyle(shortdash_dot)) ylab(, nogrid) ytitle(`c')
				plotregion(fcolor(white)) graphregion(fcolor(white))
				xline(2000 2007, lpattern(solid) lcolor(gs14))
				`v';
				
		graph export "${output}Main Figures/AF7.pdf", replace;
		
};

*************************************************************;
*APPENDIX FIGURE 8;
*************************************************************;
*See do file "appendix figure 8.do"
